from constant import *


class ZombieMessage:
    def __init__(self, name: str, zombie_property: str, zombie, zombie_path: str, pace: str | int, dmg: int, hp: int):
        self.name = name
        self.property = zombie_property
        self.zombie = zombie
        self.zombie_path = zombie_path
        self.pace = pace if isinstance(pace, int) else ZOMBIES_PACE[pace]
        self.dmg = dmg
        self.hp = hp


class ZombieObject(GifObject):
    def __init__(self, screen: pg.Surface, zombie: ZombieMessage, row):
        super().__init__(screen, zombie.zombie_path)
        self.row = row
        self.dmg = zombie.dmg
        self.property = zombie.property
        self.trajectory = points_trajectory((SCREEN_WIDTH - 144, row * LAWN_HEIGHT),
                                            (144, row * LAWN_HEIGHT), zombie.pace)
        self.total_hp = zombie.hp
        self.now_hp = zombie.hp
        self.hp = HP(screen, self.total_hp, self.now_hp, self.trajectory[0])
        self.over = False

    def update(self):
        if self.now_hp <= 0:
            self.over = True
        self.coordinate = self.trajectory[self.trajectory_number]
        self.hp.now_hp = self.now_hp
        self.hp.coordinate = self.coordinate
        self.screen.blit(self.state[self.frame_number], self.trajectory[self.trajectory_number])
        self.hp.update()
        self.frame_number = self.frame_number + 1 if self.frame_number < self.state_cycle - 1 else 0
        self.trajectory_number += 1 if self.trajectory_number < self.trajectory_cycle - 1 else 0


class Zombie(ZombieObject):
    def __init__(self, screen: pg.Surface, row):
        zombie = ZombieMessage('Zombie', 'grassland', Zombie, 'images\\Zombies\\Zombie\\Zombie.gif', '正常', 10, 100)
        super().__init__(screen, zombie, row)
